$.charge = function(lHTTP,lPop,$scope){
    var amount = 0;
    var pay10 = 1000;
    var pay50 = 5000;
    var pay100 = 10000;
    var t = undefined;

    $('.charge .charge-user-money').text('余额：'+userMoney.toFixed(1)+'元');
    $('.charge .charge-user-preMoney').text('押金：'+preMoney.toFixed(1)+'元');

    //查询用户信息
    $.updateUserInfo = function(){
        //$.getJSON(requestHost+"UserGet?callback=?&access_token="+access_token,function(json){
            lHTTP.jsonp("/UserGet?static=1")
                .success(function(json,status){
            if(parseFloat(json.user.money) > userMoney) {
                clearInterval(t);
                //储存用户金额
                userMoney = parseFloat(json.user.money);
                //储存用户赠送金额
                presentMoney = parseFloat(json.user.presentMoney);
                //储存押金
                preMoney = parseFloat(json.user.preMoney);

                $('.charge .charge-user-money').text('余额：' + userMoney.toFixed(1) + '元');
                $('.charge .charge-user-preMoney').text('押金：' + preMoney.toFixed(1) + '元');
            }
        });
    }

    var isRetunBuy = getQueryString(window.location,"result");
    if(isRetunBuy != "" && isRetunBuy != null){
        if(isRetunBuy == "success"){
            access_token = getCookie("pengtao_access_token");
            $.updateUserInfo();
        }
    }

    //拉起支付
    var prepaid2 = function(){
        //$('#charge-button').click(function(){
            //$.getJSON(requestHost+"chargeCreate?callback=?&access_token="+access_token+"&channel=wx_pub&amount="+amount,function(json){
                lPop.popSet(2 , $scope ,"支付中" ,undefined , "images/loding-icon.png" , undefined,undefined , "请稍后" , undefined,undefined);
                lHTTP.jsonp("/chargeCreate?channel=alipay_wap&amount="+amount+"&alipayWapSuccUrl="+encodeURIComponent("http://szt.imlaidian.com/app/#/charge"))
                    .success(function(json,status){
                pingpp.createPayment(json, function(result, err) {
                    if(result == "success"){
                        //$.popUpMessage(1, "充值成功", "", "确定", null,null, null, 1);
                        lPop.popSet(2 , $scope ,"充值成功" ,undefined , "images/right-icon.png" , undefined,undefined , "确定" , undefined,3000);
                        t = window.setInterval("$.updateUserInfo()",2000);
                    }
                    else if (result == "fail") {
                        lPop.popSet(2 , $scope ,"支付失败" ,undefined , "images/prompt-icon.png" , undefined,undefined , "确定" , undefined,3000);
                    }
                    else if (result == "cancel") {
                        $scope.showPopTips = false;
                    }
                });
            })
            $.popUpIsHide();
        //})
    }


    $('.pay10').click(function(){
        //$.popUpMessage(2, "充值10元", "使用微信支付", "取消", null,"确定", "charge-button", 1);
        //alert('ok')
        lPop.popSet(2 , $scope ,"充值10元" ,"使用微信支付" , "images/prompt-icon.png" , "确定",prepaid2 , "取消" ,undefined ,undefined);
        amount = pay10;
        //$.prepaid();
    })

    $('.pay50').click(function(){
        //$.popUpMessage(2, "充值50元", "使用微信支付", "取消", null,"确定", "charge-button", 1);
        lPop.popSet(2 , $scope ,"充值50元" ,"使用微信支付" , "images/prompt-icon.png" ,  "确定", prepaid2, "取消" ,undefined ,undefined);
        amount = pay50;
        //$.prepaid();
    })

    $('.pay100').click(function(){
        //$.popUpMessage(2, "充值100元", "使用微信支付", "取消", null,"确定", "charge-button", 1);
        lPop.popSet(2 , $scope ,"充值100元" ,"使用微信支付" , "images/prompt-icon.png" , "确定",prepaid2 ,"取消" , undefined,undefined);
        amount = pay100;
        //$.prepaid();
    })

}